<?php
require_once 'common.php';
require_once 'Student.php';
require_once 'ResultData.php';
require_once 'config.php';


if (isGet()) {
    echo "不得以GET访问";
    exit;
}

$id = trim($_REQUEST['id']);


$result = new ResultData();
if ($id == "") {
    $result->code = 404;
    $result->msg = "id不能为空";
    exit(json_encode($result));
}

$student = new Student();
$result->data = $student;

$id = intval($id);

$con = mysqli_connect($servername, $username, $password, $database, $port);

if (!$con) {
    $result->code = 404;
    $result->msg = "数据库连接不上";
    exit(json_encode($result));
}


$sql = "SELECT * FROM t_student WHERE id = {$id}";

$record = $con->query($sql);

if ($record->num_rows > 0) {
    while ($row = $record->fetch_assoc()) {
        $student->id = $row['id'];
        $student->name = $row['name'];
        $student->sex = $row['sex'];
        $student->age = $row['age'];
        $student->edu = $row['edu'];
        $student->city = $row['city'];
        $student->no = $row['no'];
    }
}

mysqli_close($con);

exit(json_encode($result));
